using System;
using Carlsberg.SSPC.ContentSources;
using Winsmarts.SSPC.Common;

namespace Winsmarts.SSPC
{
    class Program
    {
        static void Main(string[] args)
        {
            try
            {
                ProgramInputs programInputs = new ProgramInputs(args);

                if (programInputs.IsValid)
                {
                    switch (programInputs.CurrentOperationTarget)
                    {
                        case OperationTarget.ContentSources:
                            if (programInputs.CurrentOperation == ProgramOperation.export)
                            {
                                HelperClass.ExportXML(programInputs);
                            }
                            else
                            {
                                HelperClass.ImportXML(programInputs);
                            }
                            break;

                        case OperationTarget.SearchScopes:
                            if (programInputs.CurrentOperation == ProgramOperation.export)
                            {
                                Carlsberg.SSPC.SearchScopes.HelperClass.ExportXML(programInputs);
                            }
                            else
                            {
                                Carlsberg.SSPC.SearchScopes.HelperClass.ImportXML(programInputs);    
                            }
                            break;

                        case OperationTarget.ManagedProperties:
                            if (programInputs.CurrentOperation == ProgramOperation.export)
                            {
                                ManagedProperties.HelperClass.ExportXML(programInputs);
                            }
                            else
                            {
                                ManagedProperties.HelperClass.ImportXML(programInputs);
                            }
                            break;

                        case OperationTarget.CrawledProperties:
                            if (programInputs.CurrentOperation == ProgramOperation.export)
                            {
                                CrawlProperties.HelperClass.ExportXML(programInputs);
                            }
                            else
                            {
                                CrawlProperties.HelperClass.ImportXML(programInputs);
                            }
                            break;

                        default:                       
                            // ignore, something is horribly wrong.
                            break;
                    }
                }
                else if (args.Length != 0)
                {
                    if (args[0] != "-help")
                    {
                        Trace.WriteLine("Invalid inputs specified. You must specify atleast a URL, Filename and requested operation", true);
                        Trace.WriteLine("For help, type \"sspc -help\"", true);
                    }
                }

            }
            catch (Exception ex)
            {
                // No flippin' idea what went wrong, lets tell the user.

                Trace.WriteLine("Catastrophic Error Occurred.", true);
                Trace.WriteLine("Error details as follows.\n\n", true);
                Trace.WriteLine(ex.ToString(), true);

                Trace.WriteLine("\n\nProgram Exiting.", true);
            }
        }
    }
}
